import schedulegui.data.InfoItem;
import java.util.Date;
import java.util.Calendar;
import java.util.ArrayList;
/**
 * Abstract class Performance - this Class is a super-class that allow you to create a performance, define it's genre (Band, Comedy, Free-podium),
 * define the place of the performance, it's start- and end-time (and his duration), and it's name. You can also see wether this performance is liked or attended.
 * 
 * @author Mathieu Reymond & Jonathan Smet
 * @version 04/05/11
 */
public abstract class Performance implements InfoItem
{
    private Date startDate = new Date();
    private Calendar cal;
    private String title;
    private String genre;
    private int duration; // In seconds
    private String description;
    private String podium;
    private ArrayList<Comment> comments = new ArrayList<Comment>();
    private boolean like = false;
    private boolean attending = false;

    /**
     * Create a new performance
     * 
     * @param title The performance's name
     * @param genre The genre (Band, Comedy, Free-podium)
     * @param description A short description of the artist and it's performance
     * @param podium The podium where the performance will be
     */
    public Performance(String title, String genre, String description, String podium)
    {
        this.title = title;
        this.genre = genre;
        this.description = description;
        this.podium = podium;
        cal = cal.getInstance();
    }
    
    /**
     * Get a short description of the artist and his performance
     * 
     * @return A short description of the artist and his performance
     */
    public String getDescription()
    {
        return description;
    }
    
    /**
     * Get the genre (Band - Comedy - Free Podium) of the performance
     * 
     * @return The genre of the performance
     */
    public String getGenre()
    {
        return genre;
    }
    
    /**
     * Give the start time of the performance
     * 
     * @return The start time of the performance
     */
    public Date getStartDate()
    {
        return startDate;
    }
    
    /**
     * Give the end time of the performance
     * 
     * @return The end time of the performance
     */
    public Date getStopDate()
    {
        cal.setTime(startDate);
        cal.add(13, duration);  // 13 is the field that correspond to SECOND
        return cal.getTime();
    }
    
    /**
     * Get the name of the performance's artist
     * 
     * @return The name of the performance's artist
     */
    public String getTitle()
    {
        return title;
    }
    
    /**
     * Let you know if this performance is attended or not
     * 
     * @return True if it is attended, false otherwise
     */
    public boolean isAttending()
    {
        return attending;
    }
    
    /**
     * Let you know if this performance is liked or not
     * 
     * @return True if it is liked, false otherwise
     */
    public boolean isLiked()
    {
        
        return like;
    }
    
    /**
     * Set the start time of the performance
     * 
     * @param hour The hour of the start time
     * @param minute The minute of the start time
     */
    public void setStartDate(int hour, int minute)
    {
        cal.setTime(startDate);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        startDate = cal.getTime();
    }
    
    /**
     * Set the duration of the performance (this will also define/modify it's end-date)
     * 
     * @param newDuration The new duration of the performance
     */
    protected void setDuration(int newDuration)
    {
        duration = newDuration;
    }
    
       /**
     * The methode allows the user to write a comment to the performance.
     * 
     * @param userToComment The user that will write the comment.
     * @param comment The comment that is going to written.
     *  
     */
    public void writeComment(User userToComment, String comment)
    {
        comments.add(new Comment(userToComment, comment, title));
    }
    
       /**
     * The methode returns an Arraylist of the comments.
     * 
     *  @return The arraylist of comments
     */
    public ArrayList<Comment> getComments()
    {
        return comments;
    }
    
       /**
     * The methode returns the podium of the performance
     * 
     *  @return The podium where the performance is going to happen
     */
    public String getPodium()
    {
        return podium;
    }
    
       /**
     * The methode returns the number of likes
     * 
     * @return The number of likes
     *  
     */
    public int getNumberLikes()
    {
         int index=0;
        int t= 0;
        int counter = 0;
        while ( index< UserData.getNameList().length)
        {
            while (t< UserData.getUserData().get(UserData.getNameList()[index]).getLikeList().size())
            {
                
                if (title.equals(UserData.getUserData().get(UserData.getNameList()[index]).getLikeList().get(t)))
                {
                    counter++;
                }
                t++;
            }
            index++;
            
        }
         
        return counter;
    }
    
       /**
     * The methode returns the number of people attending the performance
     * 
     * @return The number of people attending the performance
     *  
     */
    public int getNumberAttending()
    {
        int index=0;
        int t= 0;
        int counter = 0;
        while ( index< UserData.getNameList().length)
        {
            while (t< UserData.getUserData().get(UserData.getNameList()[index]).getPlanning().getPlanningList().size())
            {
                
                if (title.equals(UserData.getUserData().get(UserData.getNameList()[index]).getPlanning().getPlanningList().get(t)))
                {
                    counter++;
                }
                t++;
            }
            index++;
        } 
        return counter;
    }
    
       /**
     * The methode returns the details of the performance
     * 
     * @returns the details
     *  
     */    public String getDetails()
    {
        
        int likeCounter= getNumberLikes();
        int attendCounter = getNumberAttending();
        String details = "Genre : " + genre + "                (" + attendCounter + " attending  and "  + likeCounter + " Likes)\n"+ "Description : " + description +  "\n " + "Duration : " + duration/60 +
        "minutes\n " + "Podium : " + podium + "\n";
        return details;
    }
    
       /**
     * The methode returns the amount of comments
     * 
     * @return The amount of Comments
     */
    public int getAmountComments()
    {
        int Amount = comments.size();
        return Amount;
    }
    
    public void setLike(boolean likeToSet)
    {
        like = likeToSet;
    }
    
    public void setAttending(boolean attendingToSet)
    {
        attending = attendingToSet;
    }
}
